#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int num[6]={1,2,4,7,15,34}; 
	int pos1=lower_bound(num,num+6,7)-num;    //返回数组中第一个大于或等于被查数的值 返回的是指针或迭代器
	int pos2=upper_bound(num,num+6,7)-num;    //返回数组中第一个大于被查数的值
	cout<<pos1<<" "<<num[pos1]<<endl;
	cout<<pos2<<" "<<num[pos2]<<endl;                      
	
    vector<int> nums{1,2,3,4,5,6,7,8};
    int p1 = upper_bound(nums.begin(), nums.end(), 5) - nums.begin(); // >
    int p2 = lower_bound(nums.begin(), nums.end(), 5) - nums.begin(); // >=
    cout << p1 << " " << p2 << endl;
    cout << nums[p1] << " " << nums[p2] << endl;

    return 0;
}